<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="java.util.*"  %>
<%@ page import="java.net.*"  %>
<%@ page import="it.univpm.diiga.semanticsearch.servizi.*"  %>
<%@ page import="it.univpm.diiga.semanticsearch.ricerca.*"  %>
<%  //page import="ricerca.UpdateRankService"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search Results</title>

<script type="text/JavaScript">
$(document).ready(function(){
 $("form#search").submit(function(){
  if($("#keyword").val()==""){
      window.location.reload();
      return false;
  }
   if($(":checked").length==0){
      window.location.reload();
      return false;
  }
    return true;
 });
});

</script>


</head>
<body>
<%
	
	

	//ArrayList link=new ArrayList();
	//Criterio_ranking updateSave=new Criterio_ranking(link,5);
	//out.println(request.getParameter("keyword"));	

	String keyword=request.getParameter("keyword");
	boolean publicL=request.getParameter("public") == null ? false : true;
	boolean defaultL=request.getParameter("default") == null ? false : true;
	boolean webL=request.getParameter("web") == null ? false : true;
	
%>


<div align="center" style="background:  url(img/result_logo1.png)
							   no-repeat;
							   height:160px;
							   width: 504px;
							   margin-top:30px;
							   margin-left:45px;">
	<br /><br />		   
	<div style="margin-top:0px;
				margin-left:100px;">					
	
	<form name="search" id="search" method="get" action="result.jsp">
		<input type="text" name="keyword" size="30" value="<%= request.getParameter("keyword") %>">
		<input type="submit" value="Search">
		<br />
		<!-- <input type="checkbox" name="local" value="local">Local Repository -->
		<input type="checkbox" name="public"  value="public" <% if (publicL) out.println("checked"); %>>Public Repository
		<input type="checkbox" name="default" value="default" <% if (defaultL) out.println("checked"); %>>Default Repository
		<input type="checkbox" name="web" value="web" <% 	if (webL) out.println("checked");  %> >Web
	</form>
	</div>
	
</div>


<%
	int sizeRepo=0;
	int sizeWeb=0;
	String color="FFFFFF";
	int count=0;

	//UpdateRankService upd=new UpdateRankService(5);
	

	List<Link> resultRepo=new ArrayList<Link>(); 
	List<Link> resultWeb=new ArrayList<Link>(); 
	
	
	try{
		if ( (publicL) || (defaultL)){
			RicercaRepository ricRepo=new RicercaRepository(false,defaultL,publicL);
			resultRepo=ricRepo.execSearch(keyword);
			sizeRepo=resultRepo.size();
		}
		
		if (webL){
			RicercaWeb ricWeb=new RicercaWeb();
			resultWeb=ricWeb.execSearch(keyword);
			sizeWeb=resultWeb.size();					
		}
		if ((sizeWeb+sizeRepo)==0)
			out.println("La ricerca non ha prodotto risultati");
		else
			out.println("La ricerca ha prodotto "+(sizeWeb+sizeRepo)+" risultati");
		
%>

<br />
<br />
<div style="margin-left:50px;width:960px;margin-top:0px">
	<div style=" 				color:white;
								font-size:16px;
								background-color:#000066;
								width:960px;
								float: left;">
		<div style="float:left;width:200px;"><b>SERVICE NAME</b></div>
		<div style="float:left;width:300px;"><b>REPOSITORY</b></div>
		<div style="float:left;width:460px;"><b>VIEW FILE</b></div>	
	</div>

<% 

	
	for (int i=0;i<sizeRepo;i++){
		if (count%2==0)
			color="#78A4EB";
		else
			color="#B7CFF9";
		
		count++;
%>		
	<div id="row<%= count %>" onmouseover="this.style.background='#FCE901'" onmouseout="this.style.background='<%= color %>'" style="font-size:12px;
										background-color: <%= color %>;
										width:960px;
										float: left;">						<!-- singola riga di risultati -->
		<div style="float:left;width:200px;"><%= resultRepo.get(i).getServName() %></div>
		<div style="float:left;width:300px;">
		<% 
		if(resultRepo.get(i).getServRepo().startsWith("http://localhost")){
			out.println("Public Repository");}
		else{
			out.println(resultRepo.get(i).getServRepo());}	
		%>
			
		</div>
		<div style="float:left;width:460px;">	WSDL: <a href="<%= resultRepo.get(i).getWsdlLink() %>"  target="_blank"> <%= resultRepo.get(i).getWsdlLink()%>  </a><br />
												BPEL: <a href="<%= resultRepo.get(i).getBpellLink() %>"  target="_blank"> <%= resultRepo.get(i).getBpellLink()%> </a><br />
												SWSAL: <a href="<%= resultRepo.get(i).getWsdlLink() %>"  target="_blank"> <%= resultRepo.get(i).getSwsalLink() %> </a>
												</div>	
	</div> 
		
			
			
<%
	}
	
			
	for (int i=0;i<sizeWeb;i++){	
		if (count%2==0)
			color="#78A4EB";
		else
			color="#B7CFF9";
			
			count++;
			
		String wsdl=resultWeb.get(i).getWsdlLink();	
		String bpel=resultWeb.get(i).getBpellLink();
		String swsal=resultWeb.get(i).getSwsalLink();
				
			
%>
	<div id="row<%= count %>" onmouseover="this.style.background='#FCE901'" onmouseout="this.style.background='<%= color %>'" 
								style="font-size:12px;
										background-color: <%= color %>;
										width:960px;
										float: left;">						<!-- singola riga di risultati -->
		<div style="float:left;width:200px;"><%= resultWeb.get(i).getServName() %></div>
		<div style="float:left;width:300px;"><% out.println(resultWeb.get(i).getServRepo()); %></div>
		<div style="float:left;width:460px;">	WSDL: <a  href="updateRank.jsp?servName=<%= resultWeb.get(i).getServName() %>&servlink=<%=resultWeb.get(i).getServLink()%>&wsdl=<%=wsdl%>" target="_blank"> <%= wsdl  %>  </a><br />
												BPEL: <a  href="updateRank.jsp?servName=<%= resultWeb.get(i).getServName() %>&servlink=<%=resultWeb.get(i).getServLink()%>&bpel=<%= bpel %>"  target="_blank"> <%= bpel %> </a><br />
												SWSAL: <a href="updateRank.jsp?servName=<%= resultWeb.get(i).getServName() %>&servlink=<%=resultWeb.get(i).getServLink()%>&swsal=<%= swsal %>" target="_blank"> <%= swsal %> </a>
												</div>	
	</div> 
		<%
		
		//
	}	
	
	}
	
	catch (Exception e) {	
		//out.println("errore result");
		//out.println(e.getMessage()+"<br />");
		//out.println(e.getStackTrace()+"<br />");
		//out.println(e.getCause()+"<br />");
	}
	
%>
</div>	
</body>
</html>